package com.TexasHoldem.db;

import java.io.FileInputStream;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;

import javax.sql.DataSource;

import org.apache.commons.dbcp.BasicDataSourceFactory;
import org.apache.commons.lang.time.DateUtils;

public class TexasHoldemDB {
	public static Properties properties;
	public static DataSource dataSource;
	public static TexasHoldemDB instance;
	static {
		try {
			properties = new Properties();
			InputStream is = new FileInputStream("conf/dbcpconfig.properties"); 
			properties.load(is);
			dataSource = BasicDataSourceFactory.createDataSource(properties);

		} catch (Exception e) {
			e.printStackTrace();

		}
	}

	public static TexasHoldemDB getDBConnUitl() {
		if (instance == null) {
			synchronized (TexasHoldemDB.class) {
				if (instance == null) {
					try {
						instance = new TexasHoldemDB();
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			}
		}
		return instance;
	}

	public Connection GetConnection() {
		try {
			return TexasHoldemDB.dataSource.getConnection();
		} catch (SQLException e) {
			e.printStackTrace();
			throw new RuntimeException("得到数据库连接失败！");
		}
	}
}
